from manim import *
from numpy import flip, insert

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.7)
        side=5
        radius=5/8*side
        abcd=Square(side).shift(UP*0.5)
        e=abcd.get_top()
        circle=Circle(radius=radius).next_to(e,DOWN,buff=0)
        self.add(abcd,circle,
            MathTex('E').next_to(e,UP),
            MathTex('A').next_to(abcd,UR),
            MathTex('B').next_to(abcd,DR),
            MathTex('C').next_to(abcd,DL),
            MathTex('D').next_to(abcd,UL)
        )
        self.wait()

class p2(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.7)
        side=5
        radius=5/8*side
        abcd=Square(side).shift(UP*0.5)
        e=abcd.get_top()
        circle=Circle(radius=radius).next_to(e,DOWN,buff=0)
        self.add(abcd,circle,
            MathTex('E').next_to(e,UP),
            MathTex('A').next_to(abcd,UR),
            MathTex('B').next_to(abcd,DR),
            MathTex('C').next_to(abcd,DL),
            MathTex('D').next_to(abcd,UL)
        )
        # p2
        a,d,c,b=abcd.point_from_proportion(0),abcd.point_from_proportion(0.25),abcd.point_from_proportion(0.5),abcd.point_from_proportion(0.75)
        f,g=(b+c)/2,circle.get_bottom()
        ef,fg=Line(e,f),Line(f,g)
        bf,cf=Line(b,f),Line(c,f)
        o=circle.get_center()
        oc,fc,fo=Line(o,c),Line(f,c),Line(f,o)
        cg,ce=Line(c,g),Line(c,e)
        self.add(ef,fg,
            MathTex('F').next_to(f,UR),
            MathTex('G').next_to(g,DOWN),
            Angle(ef,Line(e,a),elbow=True),
            MathTex(r'\frac{x}{2}').move_to([-1.25,-1.6,0]),
            MathTex(r'\frac{x}{2}').move_to([1.25,-1.6,0]),
            MathTex('x').move_to([0.2,0.5,0]),
            MathTex('2r-x').move_to([0.5,-2.6,0])
        )
        self.wait()

class p3(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.7)
        side=5
        radius=5/8*side
        abcd=Square(side).shift(UP*0.5)
        e=abcd.get_top()
        circle=Circle(radius=radius).next_to(e,DOWN,buff=0)
        self.add(abcd,circle,
            MathTex('E').next_to(e,UP),
            MathTex('A').next_to(abcd,UR),
            MathTex('B').next_to(abcd,DR),
            MathTex('C').next_to(abcd,DL),
            MathTex('D').next_to(abcd,UL),
            

        )
        # p2
        a,d,c,b=abcd.point_from_proportion(0),abcd.point_from_proportion(0.25),abcd.point_from_proportion(0.5),abcd.point_from_proportion(0.75)
        f,g=(b+c)/2,circle.get_bottom()
        ef,fg=Line(e,f),Line(f,g)
        bf,cf=Line(b,f),Line(c,f)
        o=circle.get_center()
        oc,fc,fo=Line(o,c),Line(f,c),Line(f,o)
        cg,ce=Line(c,g),Line(c,e)
        self.add(ef,fg,oc,
            MathTex('F').next_to(f,UR),
            MathTex('G').next_to(g,DOWN),
            MathTex('O').next_to(o),
            Angle(ef,Line(e,a),elbow=True),
            Angle(fc,fo,elbow=True),

        )
        self.wait()

class p4(MovingCameraScene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.7)
        side=5
        radius=5/8*side
        abcd=Square(side).shift(UP*0.5)
        e=abcd.get_top()
        circle=Circle(radius=radius).next_to(e,DOWN,buff=0)
        self.add(abcd,circle,
            MathTex('E').next_to(e,UP),
            MathTex('A').next_to(abcd,UR),
            MathTex('B').next_to(abcd,DR),
            MathTex('C').next_to(abcd,DL),
            MathTex('D').next_to(abcd,UL)
        )
        # p2
        a,d,c,b=abcd.point_from_proportion(0),abcd.point_from_proportion(0.25),abcd.point_from_proportion(0.5),abcd.point_from_proportion(0.75)
        f,g=(b+c)/2,circle.get_bottom()
        ef,fg=Line(e,f),Line(f,g)
        bf,cf=Line(b,f),Line(c,f)
        o=circle.get_center()
        oc,fc,fo=Line(o,c),Line(f,c),Line(f,o)
        cg,ce=Line(c,g),Line(c,e)
        self.add(ef,fg,oc,cg,ce,
            MathTex('F').next_to(f,UR),
            MathTex('G').next_to(g,DOWN),
            MathTex('O').next_to(o),
            Angle(ef,Line(e,a),elbow=True),
            Angle(fc,fo,elbow=True),
            Angle(cg,ce,elbow=True),
        )
        self.wait()